package com.example.easypoi.demo3.handler;

import cn.afterturn.easypoi.handler.inter.IExcelDictHandler;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * dict下拉列表
 */
public class ExcelDictAddressListHandlerImpl implements IExcelDictHandler {
    /**
     * 返回字典所有值
     * key: dictKey
     *
     * @param dict 字典Key
     * @return List<Map>
     */
    @Override
    public List<Map> getList(String dict) {
        List<Map> list = new ArrayList<>();
        Map<String, String> dictMap = new HashMap<>();
        dictMap.put("dictKey", "0");
        dictMap.put("dictValue", "女孩子");
        list.add(dictMap);
        dictMap = new HashMap<>();
        dictMap.put("dictKey", "1");
        dictMap.put("dictValue", "男孩子");
        list.add(dictMap);
        return list;
    }

    @Override
    public String toName(String dict, Object obj, String name, Object value) {
        if ("sexDictPullDownList".equals(dict)) {
            int level = Integer.parseInt(value.toString());
            switch (level) {
                case 1:
                    return "男孩子";
                case 0:
                    return "女孩子";
            }
        }
        return null;
    }

    @Override
    public String toValue(String dict, Object obj, String name, Object value) {
        if ("sexDictPullDownList".equals(dict)) {
            switch ((String) value) {
                case "男孩子":
                    return "1";
                case "女孩子":
                    return "0";
            }
        }
        return null;
    }
}